import { CommonModal } from "@/views/components/CommonModal";
import { useEffect, useState } from "react";
import { SearchSimpleTable } from "@/views/components/SearchTable/index";
import { useTableConfig } from "@/views/components/SearchTable/hooks/useTableConfig";
import { getGoodsSystemSpuLogPage, getGoodsSystemSkuLogPage } from "@/pages/GoodsModule/systemGoods/service";

import useLogColumns from "./logColumns";

function SelectLogModal(props) {
	const { logType, record, onCancel } = props;
	function handleOk() {
		onCancel;
	}
	const { columns, isSkuType } = useLogColumns({ logType, isSkuType });

	const tableRequest = isSkuType && logType == 1 ? getGoodsSystemSkuLogPage : getGoodsSystemSpuLogPage;
	const tableKey = "SelectLogModal1231";
	const { fetchList, query, searchSimpleTableProps } = useTableConfig({
		tableKey,
		rowKey: "id",
		columns,
		tableRequest,
		autoFetch: false,
		hasPagination: true,
		hasQuickSearch: false,
		beforeQuerySearch: ({ API_DATA }) => {
			return {
				...API_DATA,
				logType: logType
			};
		},
		resetSourceData: false,
		hasColsSetting: false,
		hasToggleSearchForm: false,
		columnResize: false
	});
	useEffect(() => {
		fetchList();
	}, [isSkuType]);
	return (
		<CommonModal
			title={{ title: logType == 1 ? "修改日志" : "删除日志" }}
			open={true}
			className="views-table-dialog"
			width="1296px"
			height="491px"
			onOk={handleOk}
			onCancel={props.onCancel}
		>
			<div className="views-container" style={{ height: 420 }}>
				<SearchSimpleTable key={tableKey} {...searchSimpleTableProps} />
			</div>
		</CommonModal>
	);
}

export default SelectLogModal;
